package georah.map.providers
{

	import georah.carto.Extent;
	import georah.carto.IGISClient;
	import georah.carto.PanZoom;
	import georah.map.layers.IDynamicLayerProvider;

	/**
	 *
	 * @author yuanm
	 */
	public final class WMS implements IDynamicLayerProvider
	{
		private var _baseurl:String="";

		private var _format:String="image/png";

		private var _layerHeight:Number=NaN;

		private var _layerURL:String=null;

		private var _layerWidth:Number=NaN;

		public final function get baseURL():String
		{
			return _baseurl;
		}

		public final function set baseURL(value:String):void
		{
			_baseurl=value;
		}

		public final function get format():String
		{
			return _format;
		}

		public final function set format(value:String):void
		{
			_format=value;
		}

		public final function get layerHeight():Number
		{
			return _layerHeight;
		}

		public final function get layerURL():String
		{
			return _layerURL;
		}

		public final function get layerWidth():Number
		{
			return _layerWidth;
		}

		public final function update(view:IGISClient):void
		{
			var bbox:Extent=PanZoom(view.camera).calcBBox(view.width, view.height);

			_layerWidth=view.width;
			_layerHeight=view.height;
			_layerURL=baseURL + "request=getmap&format=" + format + "&srs=EPSG:" + view.camera.where.SRID + "&bbox=" + bbox.minX + "," + bbox.minY + "," + bbox.maxX + "," + bbox.maxY + "&width=" + view.width + "&height=" + view.height;
			trace(_layerURL);
		}

	}
}
